package com.zyg.apart.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.zyg.apart.model.Lessee;
import com.zyg.apart.model.Logistics;
import com.zyg.apart.service.LesseeService;
import com.zyg.apart.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 后勤
 */
@Controller
@RequestMapping("/log")
public class LogisticsController {
	@Autowired
	private LogisticsService logisticsService;


	@RequestMapping("/list")
	public String list(Integer currentPage, Model model){
		if (currentPage == null){
			currentPage = 1;
		}
		PageInfo<Map<String,Object>> logs = logisticsService.getAllLog(currentPage);
		model.addAttribute("logs",logs);
		return "log/list";
	}

	@RequestMapping("/detail")
	public String detail(Model model,Integer id){
		Logistics log = logisticsService.getLogById(id);
		model.addAttribute("log",log);
		return "log/detail";
	}

	@RequestMapping("/toEdit")
	public String toEdit(Model model, Integer id){
		Logistics log = logisticsService.getLogById(id);
		model.addAttribute("log",log);
		return "log/edit";
	}

	@RequestMapping("/edit")
	public String edit(Logistics logistics){
		int i = logisticsService.editLog(logistics);
		return "forward:list";
	}

	@RequestMapping("/del")
	public String del(Integer id){
		int i = logisticsService.delLog(id);
		return "forward:list";
	}

	@RequestMapping("/toAdd")
	public String toAdd(){
		return "log/add";
	}

	@RequestMapping("/add")
	public String add(Logistics logistics){
		System.out.println(logistics);
		int i = logisticsService.addLog(logistics);
		return "forward:list";
	}


}
